package com.lol.ocr


import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatTextView
import com.ysw.test.R
import com.ysw.test.widget.LinearLayoutManager
import com.ysw.test.widget.RecyclerView

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<RecyclerView>(R.id.rv).apply {
            layoutManager = LinearLayoutManager(this@MainActivity)
            adapter = TestAdapter()
        }
    }

    class TestAdapter: RecyclerView.Adapter<TestAdapter.TestVH>() {
        class TestVH(v: View): RecyclerView.ViewHolder(v) {
            val tv: AppCompatTextView = v.findViewById(R.id.tv)
        }

        val data = mutableListOf(
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
        )

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TestVH {
            return TestVH(
                LayoutInflater.from(parent.context).inflate(R.layout.test_item, parent, false)
            )
        }

        override fun onBindViewHolder(holder: TestVH, position: Int) {
            holder.tv.text = data[position]
        }

        override fun getItemCount(): Int {
            return data.size
        }
    }
}